﻿#ifndef RobotServerPC_H
#define RobotServerPC_H

#include "RobotServer.h"
#include "RobotCmdNode.hpp"
#include <mutex>
#include<condition_variable>

class QSharedMemory;

class RobotServerPC : public RobotServer
{
    Q_OBJECT
public:
    explicit RobotServerPC(quint16 usPort, int argc, char** argv, QObject *parent = nullptr);
    ~RobotServerPC();

    // void call_tirgger(int leftT, int rightT);
    // void call_setGenRParam(int missionNum, const QString& serial);
    // void call_opreate(int execStep, const QString& serial);
    void call_processSLAM();
    void call_slamPos(float x, float y, float z, float rx, float ry, float rz);

protected:
    virtual int parse(unsigned char *buff, qint64 len);

    void call_sendBaCloud();

private slots:
    // void trigger(int leftT, int rightT);
    void processSLAM();
    void slamPos(float x, float y, float z, float rx, float ry, float rz);
    void sendBaCloud();


private:
    void rosSpinThread();
    std::shared_ptr<RobotCmdNode> m_robotCmdNode;
    int argc_;
    char** argv_;
    std::thread m_ros_spin_thread;

private:
    void processJson(const QVariantMap& json);

    std::thread m_threadProcessPc;
    void processPc_proc();
    void processPc();

    // void setSendRsPosData(const QVariantMap& left, const QVariantMap& right, const QString& serial);
    // void onGenRReady(int curStep, int totalStep, int operate, const QVariantList& steps);

private:
    QSharedMemory* m_smBaSend;
    QSharedMemory* m_smSLAM;   // 在此处创建，用于存储SLAM的数据
    bool m_bRunRealsense;

    QByteArray m_baCloud;
    std::mutex m_mutexBaCloud;
};

#endif // RobotServerPC_H
